


class ChainNode:
    value=None
    next=None

    def __init__(self,value=None):
        self.value=value


class ChainQueue:

    def __init__(self):
        self.front=ChainNode()
        self.rear=self.front
        pass

    def is_empty(self):
        return self.front==self.rear

    def is_full(self):
        # 链表节点构成的queue不可能慢
        return False

    def enqueue(self,ele):
        self.rear.next=ChainNode(ele)
        self.rear=self.rear.next
        pass

    def dequeue(self):
        if self.is_empty():
            raise Exception('队列为空')
        else:
            self.front=self.front.next

    def get_head(self):
        if self.is_empty():
            raise Exception('队列为空')
        else:
            return self.front.next.value



    def get_tail(self):
        if self.is_empty():
            raise Exception('队列为空')
        else:
            return self.rear.value


if __name__ == '__main__':
    queue=ChainQueue()

    queue.enqueue(1)
    print(queue.get_head(),queue.get_tail())
    queue.enqueue(2)
    print(queue.get_head(),queue.get_tail())
    queue.enqueue(3)
    print(queue.get_head(),queue.get_tail())
    queue.enqueue(4)
    print(queue.get_head(),queue.get_tail())
    queue.enqueue(5)
    print(queue.get_head(), queue.get_tail())
    queue.dequeue()
    print(queue.get_head(), queue.get_tail())
    queue.dequeue()
    print(queue.get_head(), queue.get_tail())
    queue.dequeue()
    print(queue.get_head(), queue.get_tail())
    queue.dequeue()
    print(queue.get_head(), queue.get_tail())
    queue.dequeue()
    print(queue.get_head(), queue.get_tail())
    queue.dequeue()
    print(queue.get_head(), queue.get_tail())